package com.example.liuxing.android.activity.main;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.liuxing.android.R;

/**
 * Created by liuxing on 2017/6/21.
 */

public class SplashActivity extends Activity {

    private RelativeLayout rl_splash_root; // 根布局
    private TextView tv_splash_version_name; // 版本名
    private TextView tv_splash_version_number; // 版本号

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        initView();
        initData();

        statHome();
    }

    private void initView() {
        setContentView(R.layout.splash_main);
        rl_splash_root = (RelativeLayout)findViewById(R.id.rl_splash_root);
        tv_splash_version_name = (TextView)findViewById(R.id.tv_splash_version_name);
        tv_splash_version_number = (TextView)findViewById(R.id.tv_splash_version_number);
    }

    // 初始化数据
    private  void  initData() {
        // 包管理者
        PackageManager manager = getPackageManager();
        try {
            PackageInfo info = manager.getPackageInfo(getPackageName(), 0);
            int versionCode = info.versionCode;
            String versionName = info.versionName;
            //  设置
            tv_splash_version_name.setText(versionName);
            tv_splash_version_number.setText(versionCode+"");

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    //进入主界面
    private void statHome() {
        Intent intent = new Intent(SplashActivity.this, HomeActivity.class);
        startActivity(intent);
        finish();
    }

}
